import Databus from '../databus'
const databus = new Databus()

export default class Land {
    constructor(){
        this.image = databus.imgObj.land
        // 位置
        this.x = 0
        this.y = databus.canvas.height - this.image.height
        // 宽高
        this.w = this.image.width
        this.h = this.image.height
        databus.addActor(this)
    }
    update(){
        this.x -= databus.speed
        // 如果图片向左移动的距离超过了画布的宽度， 就让x = 0
        if (this.x <= -this.w){
            this.x = 0
        }
    }
    render(){
        databus.ctx.drawImage(this.image, this.x, this.y, this.w, this.h)
        databus.ctx.drawImage(this.image, this.x + this.w, this.y, this.w, this.h)
        databus.ctx.drawImage(this.image, this.x + this.w * 2, this.y, this.w, this.h)
    }
}